package com.javashizhan.demo.mybatis.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.javashizhan.demo.mybatis.domain.User;
import com.javashizhan.demo.mybatis.service.UserService;

@Component
@RestController
public class UserController {

	@Autowired
	private UserService userService;

	@RequestMapping("/findUserByName")
	public User findUserByName(@RequestBody String name) throws Exception {
		return userService.findUserByName(name);
	}

	@RequestMapping("/createUser")
	public String createUser(@RequestBody User user) throws Exception {
		userService.createUser(user);
		return "Create success.";
	}

	@RequestMapping("/deleteUserByName")
	public String deleteUserByName(@RequestBody String name) throws Exception {
		int deleteCount = userService.deleteUserByName(name);
		return deleteCount + " record(s) be deleted.";
	}
}
